#include "head.h"

void OPEN_ERR(int fd)
{
    if (fd == -1)
    {
        perror("Error");
    }
}

int main(int argc, char const *argv[])
{
    while (1)
    {
        int fd = open("1.txt", O_RDWR | O_APPEND, 0666); // 以读写模式打开 并且 清空写
        OPEN_ERR(fd);                                   // 判断是否错误
        time_t now;
        time(&now);
        struct tm *local_time = localtime(&now);
        char buff[1024];
        strftime(buff, sizeof(buff), "%Y-%m-%d %H:%M:%S\n", local_time);
        lseek(fd, 0, SEEK_SET);
        write(fd, buff, strlen(buff));
        close(fd);
        sleep(1);
    }
    return 0;
}